<?php
declare (strict_types = 1);

namespace app\validate\api;

use app\validate\BaseValidate;
use think\Validate;
use app\model\Order;
class Comment extends BaseValidate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'product_id'=>'require',
        'order_id'=>'require',
        'contents'=>'require',
        'score'=>'require',
        'order_id'=>'require|orderStatus'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [];

    protected $scene = [
        'list'  =>  ['product_id'],
    ];

    protected function orderStatus($value)
    {
      return  (Order::where('id',$value)->value('status')) ==10 ? '該訂單還未支付，無法評論！' : true;
    }
}
